/**
 * 结论: 修饰静态的方法是通过字节码的flags来标识的,如果flags里面包含了ACC_STATIC, ACC_SYNCHRONIZED
 * 那么JVM在执行的时候就知道当前的方法是一个静态的同步方法,在执行该方法的时候后首先获取到Class对象
 * 的Monitor锁,其他线程则无法获取该Monitor对象,并陷入等待状态,直到该方法执行完并释放Class类型的对象
 * 的Monitor锁以后其他线程才可以获取到该锁。
 */
public class Demo2 {

    public synchronized static void test() {
            System.out.println("hello world2");
    }
}

//F:\SpringBoot-Learning\Chanpter-sync\target\test-classes>javap -v Demo2.class
//Classfile /F:/SpringBoot-Learning/Chanpter-sync/target/test-classes/Demo2.class
//  Last modified 2020-4-21; size 447 bytes
//  MD5 checksum 1cb735935fd695a9a1e3279bfa752a48
//  Compiled from "Demo2.java"
//public class Demo2
//  minor version: 0
//  major version: 52
//  flags: ACC_PUBLIC, ACC_SUPER
//Constant pool:
//   #1 = Methodref          #6.#17         // java/lang/Object."<init>":()V
//   #2 = Fieldref           #18.#19        // java/lang/System.out:Ljava/io/PrintStream;
//   #3 = String             #20            // hello world2
//   #4 = Methodref          #21.#22        // java/io/PrintStream.println:(Ljava/lang/String;)V
//   #5 = Class              #23            // Demo2
//   #6 = Class              #24            // java/lang/Object
//   #7 = Utf8               <init>
//   #8 = Utf8               ()V
//   #9 = Utf8               Code
//  #10 = Utf8               LineNumberTable
//  #11 = Utf8               LocalVariableTable
//  #12 = Utf8               this
//  #13 = Utf8               LDemo2;
//  #14 = Utf8               test
//  #15 = Utf8               SourceFile
//  #16 = Utf8               Demo2.java
//  #17 = NameAndType        #7:#8          // "<init>":()V
//  #18 = Class              #25            // java/lang/System
//  #19 = NameAndType        #26:#27        // out:Ljava/io/PrintStream;
//  #20 = Utf8               hello world2
//  #21 = Class              #28            // java/io/PrintStream
//  #22 = NameAndType        #29:#30        // println:(Ljava/lang/String;)V
//  #23 = Utf8               Demo2
//  #24 = Utf8               java/lang/Object
//  #25 = Utf8               java/lang/System
//  #26 = Utf8               out
//  #27 = Utf8               Ljava/io/PrintStream;
//  #28 = Utf8               java/io/PrintStream
//  #29 = Utf8               println
//  #30 = Utf8               (Ljava/lang/String;)V
//{
//  public Demo2();
//    descriptor: ()V
//    flags: ACC_PUBLIC
//    Code:
//      stack=1, locals=1, args_size=1
//         0: aload_0
//         1: invokespecial #1                  // Method java/lang/Object."<init>":()V
//         4: return
//      LineNumberTable:
//        line 1: 0
//      LocalVariableTable:
//        Start  Length  Slot  Name   Signature
//            0       5     0  this   LDemo2;
//
//  public static synchronized void test();
//    descriptor: ()V
//    flags: ACC_PUBLIC, ACC_STATIC, ACC_SYNCHRONIZED
//    Code:
//      stack=2, locals=0, args_size=0
//         0: getstatic     #2                  // Field java/lang/System.out:Ljava/io/PrintStream;
//         3: ldc           #3                  // String hello world2
//         5: invokevirtual #4                  // Method java/io/PrintStream.println:(Ljava/lang/String;)V
//         8: return
//      LineNumberTable:
//        line 4: 0
//        line 5: 8
//}
//SourceFile: "Demo2.java"
